/**
 * Created by zy on 2016/6/17.
 * 审核 - 非内检缺陷管理
 */
;(function($, window, document, undefined){

    // 待审核ID
    var $non_id = $('#JQ_non_id');
    // 备注
    var $remark = $('#JQ_remark');

    // 审核通过
    $('#JQ_adopt_btn').click(function(){

        var data = function(){
            var param = {};
            param.mode = true;
            param.id = function(){
                var id = $non_id.val();
                if(id){
                    return id;
                }else{
                    param.mode = false;
                }
                return '';
            }();
            param.state = '20';
            return param;
        }();

        if(data.mode){
            DyyBase.ajax(defectApi.url_external_audit(),data,function(dataset){
                if(dataset.bool){
                    $(this).MSG({
                        type: 'success',
                        content: '审核通过！',
                        yesBtnAct: DyyBase.goToPage,
                        noBtnAct: DyyBase.goToPage,
                        goToUrl: DyyBase.root_path + '/pbf/external/externalInspection.html'
                    });
                }else{
                    $(this).MSG({
                        type: 'error',
                        content: '审核未能通过！'
                    });
                }
            });
        }
    });

    // 审核不通过
    $('#JQ_notadopt_btn').click(function(){
        $(this).WIND({
            height: 280,
            title: '请填写审核不通过原因',
            actionBox:'div.zy-auditing-box',
            yesBtnAct: auditingNoPass
        });
    });

    // 审核不通过
    function auditingNoPass(callback){

        // 隐藏wind
        callback();

        var data = function(){
            var param = {};
            param.mode = true;
            param.id = function(){
                var id = $non_id.val();
                if(id){
                    return id;
                }else{
                    param.mode = false;
                }
                return '';
            }();
            param.remark = function(){
                var v = $.trim($remark.val());
                if(v){
                    return v;
                }else{
                    $remark.TIP({
                        content: '备注信息不能为空!',
                        scroll: false
                    });
                }
            }();
            param.state = '04';
            return param;
        }();

        if(data.mode){
            DyyBase.ajax(defectApi.url_external_audit(),data,function(dataset){
                if(dataset.bool){
                    $(this).MSG({
                        type: 'success',
                        content: '操作成功!',
                        yesBtnAct: DyyBase.goToPage,
                        noBtnAct: DyyBase.goToPage,
                        goToUrl: DyyBase.root_path+'/pbf/external/externalInspection.html'
                    });
                }
            });
        }
    }

    // 获取照片
    var imgarr = [];
    $('input[name="zy_image"]').each(function(){
        var $this = $(this);
        var img = '<a href="'+DyyBase.file_path+$this.val()+'" target="_blank"><img height="50" width="50" src="'+DyyBase.file_path+$this.val()+'"></a>';
        imgarr.push($this.val());
    });

    var imgObj = DyyBase.getImagePath(imgarr);
    // 填充照片
    $('#JQ_defect_image').loadSmallImage(imgObj);

    // 返回
    $('#JQ_goback_btn').click(function(){
        window.location.href = DyyBase.root_path + '/pbf/external/externalInspection.html';
    });
})(jQuery, window, document);